{% load nm %}
{% if procs %}
<table class="proctable tablesorter {{class}}">
<thead>
    <tr>
        <th>Started</th>
        <th>Last</th>
        <th>Target</th>
        <th>Applicant</th>
        <th>UID</th>
        <th>Status</th>
        <th>AM</th>
        {% if not proctable_archive %}
        <th>Requirements</th>
        {% if visitor.is_admin %}
        <th>FD comments</th>
        {% endif %}
        {% endif %}
    </tr>
</thead>
<tbody>
    {% for process in procs %}
    <tr>
        {% with process.compute_status as status %}
        <td class="word"><small>{{status.log_first.logdate|date:"Y-m-d"}}</small></td>
        <td class="word"><small>{{status.log_last.logdate|date:"Y-m-d"}}</small></td>
        <td class="word" val="{{ process.applying_for|seq_status }}">{{process.applying_for|sdesc_status}}</td>
        <td><a href="{{ process.get_absolute_url }}">{{process.person.fullname}}</a></td>
        <td><a href="{{ process.get_absolute_url }}">{{process.person.uid}}</a></td>
        <td>
        {% if process.frozen_by %}
          {% if process.approved_by %}
            Approved
          {% else %}
            Frozen for review
          {% endif %}
        {% else %}
          {% if process.approved_by %}
            Approved
          {% elif not status.requirements_missing %}
            Waiting for review
          {% else %}
            Collecting requirements
          {% endif %}
        {% endif %}
        </td>
        <td>
          {% with process.current_am_assignment as assignment %}
          {% if assignment %}{{assignment.am.person.a_link}}{% endif %}
          {% endwith %}
        </td>
        {% if not proctable_archive %}
        <td val="{{status.requirements_ok|length}}">
          {% for req in status.requirements_ok %}<a href="{{req.get_absolute_url}}">✔{{req.type_sdesc}}</a> {% endfor %}
          {% for req in status.requirements_missing %}<a href="{{req.get_absolute_url}}">✘{{req.type_sdesc}}</a> {% endfor %}
        </td>
        {% if visitor.is_admin %}
        <td>{{process.fd_comment}}</td>
        {% endif %}
        {% endif %}
        {% endwith %}
    </tr>
    {% endfor %}
</tbody>
</table>
{% endif %}
